/*
 * @Description:配置管理API
 * @Author: qingyang
 * @Date: 2023-07-20 11:49:30
 * @LastEditors: qingyang
 * @LastEditTime: 2023-07-26 15:59:00
 */

import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '../../basicModel'

import type {
  pageConfigParams,
  GetConfigListResult,
  EnergyConfigSaveParams,
  EditConfigParams,
  ListUserByOrgResult
} from './model/configModel'

enum Api {
  GET_CONFIG_LIST = '/inventory/adConfig/pageInfo',
  ENABLE_CONFIG = '/inventory/adConfig/modifyStatus',
  TEMPORARY_SAVE = '/inventory/adConfig/modifyTemporaryStorage',
  TEMPORARY_CREATE = '/inventory/adConfig/createTemporaryStorage',
  EDIT_CONFIG = '/inventory/adConfig/modifyConfig',
  CREATE_CONFIG = '/inventory/adConfig/createConfig',
  GET_TREE_LIST2 = '/upms/organization/getOrgTreeByCode',
  GET_USER_LIST = '/upms/organization/listUserByOrg',
  GET_CONFIG_DETAIL = '/inventory/adConfig/getConfigDetail',
  // 监测计划
  GET_EMISSION_LIST = '/inventory/emissionInventory/listReleasedPlanByOrgs'
}

// 填报配置分页列表
export const getConfigList = (
  params: pageConfigParams & BasicPagingListParams
): Promise<BasicPagingListResult<GetConfigListResult>> => get(Api.GET_CONFIG_LIST, params)

//
export const enableConfig = (configNo: string, status: string): Promise<void> =>
  post(Api.ENABLE_CONFIG, { configNo, status })

// 暂存配置
export const temporarySave = (params: EditConfigParams): Promise<void> =>
  post(Api.TEMPORARY_SAVE, params)
// 编辑配置
export const editConfig = (params: EditConfigParams): Promise<void> => post(Api.EDIT_CONFIG, params)

// 新建配置
export const createConfig = (params: EnergyConfigSaveParams): Promise<void> =>
  post(Api.CREATE_CONFIG, params)

export const temporaryCreate = (params: EnergyConfigSaveParams): Promise<void> =>
  post(Api.TEMPORARY_CREATE, params)

export const getConfigDetail = (configNo: string): Promise<any> =>
  get(Api.GET_CONFIG_DETAIL, { configNo })
// 指定类型的模板列表
// TODO 文档不全
export const getUserOrganizationTree = (orgCode: string): Promise<any> =>
  get(Api.GET_TREE_LIST2, { orgCode })

// 根据orgCode查排放源列表
export const getEmissionListByOrgs = (orgCodeList: string[], year: string): Promise<any> =>
  post(Api.GET_EMISSION_LIST, { orgCodeList, year })

// 指定类型的模板列表  roleCode:盘查用户  scope:盘查
export const listUserByOrg = (orgCode: string): Promise<ListUserByOrgResult[]> =>
  get(Api.GET_USER_LIST, {
    orgCode,
    scope: 'meta_data',
    roleCode: 'meta_data_review_user,meta_data_admin'
  })
